
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
 
var app = getApp();
Page({
  data: {
    qqq:'',
    yaoqing_cont:[
      '邀请成功好友','本地赚钱榜'
    ],
    yaoqing_ind:0,
    yaoqing_ok_data:[],
    yaoqing_ok_money:0,
    yaoqing_bang_data:[],
    yaoqing_zhanshi_data:[
      { p_member_name: '1111', invite_money: '11' },
      { p_member_name: '2222', invite_money: '22' },
      { p_member_name: '3333', invite_money: '33' },
      { p_member_name: '4444', invite_money: '44' },
    ],
    zhanshi_ind:0,
    timer:null,
    award_rules_data:[],
    box_bg_true:false,
    erweima:false,
    erweimaUrl:''
  },
  aaa(){},
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  box_bg_hide(){
    this.setData({
      box_bg_true: false
    })
  },
  box_bg_show() {
    this.setData({
      box_bg_true: true
    })
  },
  openerweima(){
    this.setData({
      erweima: true
    })
    this.get_qrcode();
  },
  hide_erweima(){
    this.setData({
      erweima: false
    })
  },
  // go_order_detail(){
  //   wx.navigateTo({
  //     url: '/pages/order_detail/order_detail'
  //   })
  // },
  zhanshi_tab_ind(){
    let n = this.data.zhanshi_ind;
    // console.log(n, this.data.yaoqing_zhanshi_data.length, this.data.zhanshi_ind,88);
    if (n < this.data.yaoqing_zhanshi_data.length-1) {
      n++;
    }else{
      n = 0;
    } 
    this.setData({
      zhanshi_ind: n
    })
  },
  yaoqing_btn(e){
    console.log(e.currentTarget.dataset.ind);
    this.setData({
      yaoqing_ind: e.currentTarget.dataset.ind
    })
  },
  yaoqing_ok(){
    let that = this;
    //index.php?act=other_member&op=get_invitation_list
    let k = wx.getStorageSync('key');
    wx.request({
      url: ApiUrl + 'index.php?act=other_member&op=get_invitation_list',
      data: {
        act:'other_member',
        op:'get_invitation_list',
        key:k
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
          console.log('邀请成功好友列表:==>', result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            console.log(result.data.datas);
            let res = result.data.datas.list;
            let num = 0;
            for (let i = 0; i < result.data.datas.length;i++){
              num += result.data.datas[i].invite_money;
            }


            that.setData({
              yaoqing_ok_data: res,
              yaoqing_ok_money: num
            })
          }
        }
      }
    });
  },
  yaoqing_bang() {
    let that = this;
    let k = wx.getStorageSync('key');
    //index.php?act=other&op=get_invitation_money_list
    wx.request({
      url: ApiUrl + 'index.php?act=other&op=get_invitation_money_list',
      data: {
        act: 'other',
        op: 'get_invitation_money_list',
        key: k
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            console.log(result.data.datas);
            let res = result.data.datas.list;
            that.setData({
              yaoqing_bang_data: res
            })
          }
        }
      }
    });
  },
  get_qrcode() {//小程序获取二维码
    let that = this;
    //index.php?act=other&op=get_qrcode
    let uid = wx.getStorageSync('userId');
    let url = 'pages/index/index?uid=' + uid + '&type= get_money';
    wx.request({
      url: ApiUrl + 'index.php?act=other&op=get_qrcode',
      data: {
        act: 'other',
        op: 'get_qrcode',
        url: url
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
          if (result.data.code == 200) {
            let res = result.data.datas;
            that.setData({
              erweimaUrl: res
            })

          }
      }
    });
  },
  yaoqing_zhanshi(){
      let that = this;
      //index.php?act=other&op=get_invitation_list
      wx.request({
        url: ApiUrl + 'index.php?act=other&op=get_invitation_list',
        data: {
          act: 'other',
          op: 'get_invitation_list'
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'POST',
        success: function (result) {
          if (result.statusCode == 200) {
            if (result.data.code == 200) {
              let res = result.data.datas.list;
              that.setData({
                yaoqing_zhanshi_data: res
              })

            }
          }
        }
      });
  },
  yaoqing_zhanghu() {
    let that = this;
    let k = wx.getStorageSync('key');
    //index.php?act=other&op=my_invitation
    wx.request({
      url: ApiUrl + 'index.php?act=other_member&op=my_invitation',
      data: {
        act: 'other_member',
        op: 'my_invitation',
        key: k
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            
            let res = result.data.datas;
            that.setData({
              yaoqing_zhanghu: res
            })
          }
        }
      }
    });
  },
  awardRules(){
    let that = this;
    wx.request({
      url: ApiUrl + 'index.php?act=other&op=get_invitation_setting',
      data: {
        act: 'other',
        op: 'get_invitation_setting'
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            let res = result.data.datas;
            that.setData({
              award_rules_data: res
            })
          }
        }
      }
    });
  },
  onLoad: function (option) {
    this.yaoqing_ok();
    this.yaoqing_bang();
    this.yaoqing_zhanshi();
    this.yaoqing_zhanghu();
    this.awardRules();
    if (option.uid){
      wx.setStorageSync(option.type, option);
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    let that = this;
    that.data.timer = setInterval(() => {
      that.zhanshi_tab_ind();
    }, 3000)
    console.log('监听页面显示');
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('监听页面隐藏');
    let that = this;
    clearInterval(that.data.timer);
  },
    /**
     * 生命周期函数--监听页面卸载
     */
  onUnload: function () {
    let that = this;
    clearInterval(that.data.timer);
  },
  onPullDownRefresh: function () {

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    let uid = wx.getStorageSync('userId');
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      title: '快来！狂赚600元现金！',
      imageUrl:'/image/WechatIMG91.jpeg',//图片地址
      path: '/pages/index/index?uid=' + uid +'&& type= get_money',// 用户点击首先进入的当前页面
      success: function (res) {
        // 转发成功
        console.log("转发成功:");
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:");
      }
    }

  }
})
